﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ChangeYWZL : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            InitData();

        }

    }
    public void InitData()
    {
        int YWZLid = int.Parse(Request["ID"].ToString());   //取出传递过来的试题编号
        using (DataClassesDataContext ds = new DataClassesDataContext())
        {
            var r = (from q in ds.YeWuZiLiao
                     where q.id == YWZLid
                     select q).FirstOrDefault();
            ddlCourse.DataSource = from q in ds.YeWuZiLiao
                                   where (q.parentID == null || q.parentID == -1)
                                   select q;
            ddlCourse.DataTextField = "mingcheng";
            ddlCourse.DataValueField = "id";
            ddlCourse.DataBind();
            ddlCourse.SelectedIndex = ddlCourse.Items.IndexOf(ddlCourse.Items.FindByValue(Convert.ToString( r.parentID)));
            txtTitle.Text = r.mingcheng.ToString();
            this.TextBox2.Text = r.neirong.ToString();
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid)
        {

            if (Request["ID"] != null)                                  //如果是修改题目信息
            {
                using (DataClassesDataContext ds = new DataClassesDataContext())
                {
                    int YWZLid = int.Parse(Request["ID"].ToString());   //取出传递过来的试题编号
                    var r = (from q in ds.YeWuZiLiao
                             where q.id == YWZLid
                             select q).FirstOrDefault();
                    r.parentID = int.Parse(ddlCourse.SelectedValue);//为单选题对象各属性赋值
                    r.mingcheng = txtTitle.Text;
                    r.neirong = this.TextBox2.Text;
                    ds.SubmitChanges();

                    Response.Write("<script>alert('修改成功！');</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('修改失败！');</script>");
            }

        }
    }
}